export function strFirstBit(val) {
  let arr = val.map((val, index, arr) => {
    return val.currency;
  });
  return arr;
}
export function filterArrayEmpty(val) {
  let isEmpty = val.every((val) => {
    return val != "";
  });
  return isEmpty;
}
export class WebSocket {
  constructor(params) {
    //只有params这个参数必须卸载constructor方法里，其他的实例属性可以写在外面
    // 比如 socket = null
    this.socket = null;
    this.params = params;
    this.j = 0; //websocket重连次数
    this.i = 0; //发送信息次数
  }

  init(params) {
    if (this.params.path) {
      this.path = this.params.path;
    } else {
      throw new Error("参数socket服务器地址path必须存在");
    }

    this.socket = new WebSocket(this.path);
    this.socket.onopen = () => {
      console.log("连接开启");
    };
    this.socket.onmessage = this.params.onmessage;
  }

  close() {
    clearTimeout(this.time);
    this.socket.close(1000, "手动关闭");
  }
}
